﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using ET;
namespace DA
{
    public class Order_Detail_DAL : clsConnect
    {
        private clsConnect cls = new clsConnect();
        #region[Get-Data]
        public DataTable GetOrderDetail(int id)
        {
            return cls.GetData_ID_Int("sp_tb_Order_Detail_Edit", "@Order_Id", id);
        }
        public DataTable GetOrderDetailOrder(int id)
        {
            return cls.GetData_ID_Int("sp_tb_Order_Detail_Order", "@Order_Id", id);
        }
        public DataTable GetOrderDetailTemp()
        {
            return cls.GetData("sp_tb_Order_Detail");
        }
        public DataTable GetOrderDetailTempTotal()
        {
            return cls.GetData("sp_tb_Order_Detail_Total");
        }
        #endregion

        #region[Update]
        public bool InsertOrderDetail(Order_Detail_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", data.Order_Id);
            cls.AddParameter("@Materials_Id", data.Materials_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);

            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);

            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);

            cls.AddParameter("@Order_Detail_Total_Price", data.Order_Detail_Total_Price);
            cls.AddParameter("@Order_Detail_Note", data.Order_Detail_Note);
            cls.AddParameter("@IsActive", data.IsActive);
            cls.ExecuteNonQuery("sp_tb_Order_Detail_Insert");
            return true;
        }
        public bool InsertOrderDetailTemp(OrderDetailTemp_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Materials_Id", data.Materials_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);

            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);

            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);

            cls.AddParameter("@Order_Detail_Total_Price", data.Order_Detail_Total_Price);
            cls.AddParameter("@Order_Detail_Note", data.Order_Detail_Note);
            cls.ExecuteNonQuery("sp_tb_Order_Detail_Temp_Insert");
            return true;
        }
        public bool UpdateOrderDetailTemp(OrderDetailTemp_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Detail_Id", data.Order_Detail_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);
            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);
            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);
            cls.AddParameter("@Order_Detail_Total_Price", data.Order_Detail_Total_Price);
            cls.AddParameter("@Order_Detail_Note", data.Order_Detail_Note);
            cls.ExecuteNonQuery("sp_tb_Order_Detail_Temp_Update");
            return true;
        }
        public bool UpdateOrderDetail(Order_Detail_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Detail_Id", data.Order_Detail_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);
            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);
            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);
            cls.AddParameter("@Order_Detail_Total_Price", data.Order_Detail_Total_Price);
            cls.ExecuteNonQuery("sp_tb_Order_Detail_Update");
            return true;
        }
        public bool UpdateOrderDetailStt(Order_Detail_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", data.Order_Id);
            cls.AddParameter("@IsActive", data.IsActive);
            cls.ExecuteNonQuery("sp_tb_Order_Detail_Stt");
            return true;
        }
        public bool DeleteOrderDetailTemp(int id)
        {
            cls.Delete("sp_tb_Order_Detail_Temp_Delete", "@Order_Detail_Id", id);
            return true;
        }
        public bool DeleteOrderDetailTempAll()
        {
            cls.Delete_All_DB("sp_tb_Order_Detail_Temp_Delete_All");
            return true;
        }
        #endregion
    }
}
